
import '../style/index.css';

import 'lazysizes';

import { on } from '../common/util'
import { CarouselCtl, Carousel } from '../common/Carousel'
import { SvgAnnulusloading } from '../common/SvgAnnulusloading'
import { refreshScrollAniAreas, emitScrollAniAreas } from '../common/scrollAniAreas'
import { initMenu } from './menu'
import { initNews } from './news'
import { initRouter} from "../common/Router.js";


on(window, ['resize'], refreshScrollAniAreas);
on(window, ['scroll'], emitScrollAniAreas);
on(window, ['load'], function () {
    console.log('ev load');
});
window.onload = function () {
    refreshScrollAniAreas();
    emitScrollAniAreas();

    //轮播图
    var carouselCtl = document.getElementsByClassName('carousel-ctl')[0];
    var carouselPages = document.getElementsByClassName('carousel-pages')[0];
    var carouselCtlTpl = document.getElementsByClassName('carousel-ctl-tpl')[0];
    if (carouselCtl) {
        if (!carouselCtlTpl) throw new Error('.carousel-ctl-tpl not found!');
        if (!carouselPages) throw new Error('.carousel-pages not found!');
        var createCtlHandler = function () {
            return new CarouselCtl(new SvgAnnulusloading(carouselCtlTpl, 'current', 253, 'annulusloading-svg-ring', false));
        };
        new Carousel(carouselPages, 'carousel-page', 'carousel-page-enter', 'carousel-page-exit',
            carouselCtl, createCtlHandler, 5000, 500);
    }

    //菜单
    initMenu();

    //新闻列表页面
    initNews();

    //初始化路由
    initRouter();
};
